import $ from 'jQuery';
(function () {
  let storeParams = JSON.parse(IOT.getSessionStore(URI.OPERATE.PROJECT.DETAIL.PAGE));
  let $vue = new Vue({
    el: '.project-detail-hook',
    data: {
      account: {
        'userId': 1,
        'mobile': '',
        'userName': '',
        'email': '',
        'roleName': '',
        'state': 'normal',
        'companyName': '',
        'registerTime': '',
        'gender': '',
        'genderText': ''
      }
    },
    created: function () {
      M.Request.getRoleList(true, (roleList, ret) => {
        this.roleList = roleList;
      });
      IOT.getServerData(URI.OPERATE.PROJECT.DETAIL.DATA, {userId: storeParams.userId}, (ret) => {//获取详情
        if (ret.code === 200) {
          ret.data.genderText = ret.data.gender == '1' ? '男' : '女';
          this.account = $.extend({}, this.account, ret.data);
        } else {
          IOT.tips(ret.message || '服务器请求失败，稍后再试！', 'error');
        }
      });
    },
    methods: {
      goBack: function () {
        M.Page.emitPrePage();
      },
      paramDetail: function (e, value, rowData, index) {
        M.Page.emit(URI.OPERATE.PROJECT.DETAIL.PARAM);
        IOT.setSessionStore(URI.OPERATE.PROJECT.DETAIL.PARAM, JSON.stringify(rowData));
        return false;
      }
    },
    mounted: function () {
      this.$nextTick(() => {
        let tableHookName = $('.projectDetail-table-hook');
        var $tableHook =tableHookName.bootstrapTable({
          scrollbar: 'projectDetail-table-body',
          striped: true, // 设置为 true 会有隔行变色效果
          pagination: true, // true 显示分页
          paginationDetail: true, // 分页详情
          sidePagination: 'server', // 服务器端
          method: 'post',
          url: URI.OPERATE.PROJECT.DETAIL.LIST,
          debug: false,
          cache: false,
          pageNumber: 1,
          pageSize: 20,
          pageList: [10, 20, 50, 100],
          // fixedColumns: true,
          customButton: '',
          customQueryParams: function (params) {
          },
          onLoadSuccess: function (data) {
            //console.log(JSON.stringify(data));
          },
          onLoadError: function (status, xhr) {
          },
          onCheckAll: function (rows) {
          },
          columns: [
            {
              field: 'mobile', title: '分组编号', align: 'center', fixedLeft: true,tips:true
            },
            {
              field: 'userName', title: '分组名称', align: 'center', fixedLeft: true,tips:true
            },
            {
              field: 'gender', title: '单灯数', align: 'center', fixedLeft: true,tips:true
            },
            {
              field: 'email', title: '维护人', align: 'center', fixedLeft: true,tips:true
            },
            {
              field: 'email', title: '备注', align: 'center', fixedLeft: true,tips:true
            },
            {
              field: 'registerTime', title: '创建时间', align: 'center', fixedLeft: true,tips:true,
              formatter: function (val, row, index) {
                return val;
              }
            }
          ]
        });
        //权限——查看
        if (!M.Authority.checkAuthority('account-detail')&&!M.Authority.checkAuthority('account-modify')) {
          $(tableHookName).bootstrapTable('hideColumn', 'operate');//隐藏列
        }
      });
    }
  });
})();